﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ASPItalia.ModelVirtualCasting.Silverlight.ViewModels;
using System.Windows.Printing;

namespace ASPItalia.ModelVirtualCasting.Silverlight
{
    public partial class PrintModelDetails : ChildWindow
    {
        //Grid docToPrint = new Grid();
        ListBox docToPrint = new ListBox();
        public MainViewModel ViewModel { get; private set; }

        public PrintModelDetails()
        {
            InitializeComponent();
        }

        public PrintModelDetails(MainViewModel viewModel)
            : this()
        {
            ViewModel = viewModel;
            this.DataContext = ViewModel;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void MultimediaList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
        }

        private void ChildWindow_Loaded(object sender, RoutedEventArgs e)
        {
        }

        void doc_StartPrint(object sender, StartPrintEventArgs e)
        {
            docToPrint = this.MultimediaList;
            docToPrint.Height = 600;
        }

        void doc_PrintPage(object sender, PrintPageEventArgs e)
        {
            e.PageVisual = docToPrint;
            e.HasMorePages = false;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            PrintDocument doc = new PrintDocument();
            doc.DocumentName = "Stampa";
            doc.StartPrint += new EventHandler<StartPrintEventArgs>(doc_StartPrint);
            doc.PrintPage += new EventHandler<PrintPageEventArgs>(doc_PrintPage);
            doc.EndPrint += new EventHandler<EndPrintEventArgs>(doc_EndPrint);
            doc.Print();
        }

        void doc_EndPrint(object sender, EndPrintEventArgs e)
        {
            this.DialogResult = false;
        }

    }
}

